package com.qhsolution.dbhelper;

import java.io.File;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DataHelper {
	
	private static String DB_PATH = "";
	private static String DB_NAME = "economydict.sqlite";// Database name
	private SQLiteDatabase mDataBase;
	private final Context mContext;
	
	public DataHelper(Context context)
	{
		DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
		this.mContext = context;
	}
	public boolean updateItems(String table, ContentValues values,String whereClause, String[]whereArgs)
	{
		int ret = mDataBase.update(table, values, whereClause, whereArgs);
		if(ret == 0)
			return false;
		else
			return true;
	}
	public Cursor getSelect(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
	{
		Cursor c = null;
		try{		 
			c = mDataBase.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);			
		}
		catch(Exception e)
		{
			Log.e("DbSelect_E", e.getMessage());
		}
		return c;
	}
	
	public Cursor getSelect(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy,String limit)
	{
		Cursor c = null;
		try{		 
			c = mDataBase.query(table, columns, selection, selectionArgs, groupBy, having, orderBy,limit);			
		}
		catch(Exception e)
		{
			Log.e("DbSelect_E", e.getMessage());
		}
		return c;
	}
	
	// Open the database, so we can query it
		public boolean openDataBase() throws SQLException
		{
			String mPath = DB_PATH + DB_NAME;
			// Log.v("mPath", mPath);
			mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
			// mDataBase = SQLiteDatabase.openDatabase(mPath, null,
			// SQLiteDatabase.NO_LOCALIZED_COLLATORS);
			return mDataBase != null;
		}

		public void close()
		{
			if (mDataBase != null)
				mDataBase.close();
		}

}
